/*
 *  Copyright 2008 Mark Ashworth <javameme@gmail.com>.
 * 
 *  Licensed under the GNU General Public License v3 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.gnu.org/licenses/gpl-3.0.html
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package xperiment.metaphor.model.reflection;

import xperiment.metaphor.model.AbstractBean;
import xperiment.metaphor.model.Named;

/**
 * A signure of a method including it's name and parameters
 * @author Mark Ashworth <javameme@gmail.com>
 * @version 1.0.0
 */
public class MethodSignature extends AbstractBean implements Named {
    /* The name of the method */
    private String name;
    
    /* The parameter types of the method */
    private String[] parameters = new String[0];

    /**
     * The method signature constructor
     * @param name The name of the method
     * @param parameters The parameter types
     */
    public MethodSignature(String name, String[] parameters) {
        super();
        
        if (name == null) {
            throw new IllegalArgumentException("The name of the method cannot be null");
        }
        
        this.name = name;
        this.parameters = parameters;
        if (this.parameters == null) {
            this.parameters = new String[0];
        }
    }
    
    /**
     * The name of the method
     * @return String
     */
    public String getName() {
        return this.name;
    }
    
    /**
     * The parameter types of the method
     * @return String[]
     */
    public String[] getParameters() {
        return parameters;
    }
    
    /**
     * The parameter types of the method
     * @return String[]
     * @throws ClassNotFoundException If the class represented by the String parameter value cannot be found
     */
    public Class[] getParameterTypes() throws ClassNotFoundException {
        if (this.parameters == null) {
            this.parameters = new String[0];
        }
        
        Class[] types = new Class[parameters.length];
        for(int i = 0; i < parameters.length; i++) {
            types[i] = Class.forName(parameters[i]);
        }
        return types;
    }

    @Override
    public String toString() {
        return (name == null ? "null" : name) + " ( " + (this.parameters == null ? "null" : this.parameters) + " )";
    }
}
